
package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;


public class Patient {
    
    private int PatientID;
    private String FirstName;
    private String LastName;
    private String Address;
    private String Phone;
    private float Height;
    private float Weight;
    private String BloodType;
    private int Sex;
    private String BirthDay;
    private String Notes;
    private String Email;
    private int Benificiary;
    private String InsuranceDeadline;
    
    /** Creates a new instance of Patient */
    public Patient() {
    }

    
    public int getPatientID() {
        return PatientID;
    }

    public void setPatientID(int PatientID) {
        this.PatientID = PatientID;
    }

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String FirstName) {
         this.FirstName = FirstName;
    }

    public String getLastName() {
        return LastName;
    }

    public void setLastName(String LastName) {
        this.LastName = LastName;
    }

    public String getAddress() {
        return Address;
    }

    public void setAddress(String Address) {
        this.Address = Address;
    }

    public String getPhone() {
        return Phone;
    }

    public void setPhone(String Phone) {
         this.Phone = Phone;
    }

    public float getHeight() {
        return Height;
    }

    public void setHeight(float Height) {
        this.Height = Height;
    }
    
    public float getWeight() {
        return Weight;
    }

    public void setWeight(float Weight) {
        this.Weight = Weight;
    }

    public String getBloodType() {
        return BloodType;
    }

    public void setBloodType(String BloodType) {
        this.BloodType = BloodType;
        
    }

    public int getSex() {
        return Sex;
    }

    public void setSex(int Sex) {
        this.Sex = Sex;
    }

    public String getBirthDay() {
        return BirthDay;
    }

    public void setBirthDay(String BirthDay) {
        this.BirthDay = BirthDay;
    }

    public String getNotes() {
        return Notes;
    }

    public void setNotes(String Notes) {
        this.Notes = Notes;
    }

    public String getEmail() {
        return Email;
    }

    public void setEmail(String Email) {
        this.Email = Email;
    }

    public int getBenificiary() {
        return Benificiary;
    }

    public void setBenificiary(int Benificiary) {
        this.Benificiary = Benificiary;
    }
    
    public String getInsuranceDeadline() {
        return InsuranceDeadline;
    }

    public void setInsuranceDeadline(String InsuranceDeadline) {
        this.InsuranceDeadline = InsuranceDeadline;
    }
    
    public static Vector GetPatientInHospital() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetPatientInHospital");
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    } 

        public static Vector GetPatientNotInHospital() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetPatientNotInHospital");
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    } 
        
    public static Vector GetPatientNotInHospitalByID(int id) throws SQLException
    {
        Vector v = new Vector();
        try {
            Vector paramList = new Vector();
            paramList.add(new Integer(id));  
        ResultSet rs = DBHelper.executeQuery("spGetPatientNotInHospitalByID",paramList);
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }         

    public static Vector GetPatientNotInHospitalByName(String name) throws SQLException
    {
        Vector v = new Vector();
        try {
            Vector paramList = new Vector();
            paramList.add(name);       
        ResultSet rs = DBHelper.executeQuery("spGetPatientNotInHospitalByName",paramList);
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }       
    
    public static Vector getAllPatient() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllPatients");
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }
    
    public static Vector getPatientByName(String name) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);            
            ResultSet rs = DBHelper.executeQuery("spSearchPatientByName", paramList);
            
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            // Handle exception
            
            throw sqle;
        }
        
        return v;        
    }

    public static Vector getPatientByID(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));            
            ResultSet rs = DBHelper.executeQuery("spSearchPatientByID", paramList);            
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            // Handle exception
            
            throw sqle;
        }
        
        return v;        
    }
    
    public static int insertPatient(Patient p) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(p.getFirstName());
            paramList.add(p.getLastName());
            paramList.add(p.getAddress());
            paramList.add(p.getHeight());
            paramList.add(p.getWeight());
            paramList.add(p.getPhone());
            paramList.add(p.getBloodType());
            paramList.add(p.getSex());
            paramList.add(p.getBirthDay());
            paramList.add(p.getNotes());
            paramList.add(p.getEmail());
            paramList.add(p.getBenificiary());
            paramList.add(p.getInsuranceDeadline());
            i=DBHelper.executeUpdate("spInsertPatient",paramList);            
        }catch(SQLException e){throw e;}
        return i;
    }
    
    public static int deletePatient(int id) throws  SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));                               
            i=DBHelper.executeUpdate("spDeletePatientByID",paramList);
        }catch(SQLException e){throw e;}
        return i;
    }
    public static int updatePatient(int id, Patient p) throws  SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id)); 
            paramList.add(p.getFirstName());
            paramList.add(p.getLastName());
            paramList.add(p.getAddress());
            paramList.add(p.getHeight());
            paramList.add(p.getWeight());
            paramList.add(p.getPhone());
            paramList.add(p.getBloodType());
            paramList.add(p.getSex());
            paramList.add(p.getBirthDay());
            paramList.add(p.getNotes());
            paramList.add(p.getEmail());
            paramList.add(p.getBenificiary());
            paramList.add(p.getInsuranceDeadline());
            i=DBHelper.executeUpdate("spUpdatePatientByID",paramList);            
        }catch(SQLException e){throw e;}
        return i;
    }
    
    public static int getCaseIDInHospital(int i)
    {
        int id=0;
        try{
            id=DBHelper.executeSelect("spGetCaseIDInHospital",i);            
        }catch(SQLException e){e.printStackTrace();}
        return id;
    }
    
    public static int getTreatIDInHospital(int i) throws SQLException
    {
        int id=0;
        try{
            id=DBHelper.executeSelect("spGetTreatIDInHospital",i);            
        }catch(SQLException e){throw e;}
        return id;
    }
    
    public static Vector AdvanceSearchPatient(String name, int year, String address, String blood) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(name);
            paramList.add(new Integer(year));
            paramList.add(address);
            paramList.add(blood);
            ResultSet rs = DBHelper.executeQuery("spAdvanceSearchPatient", paramList);            
            while(rs.next()){
                Patient p = new Patient();
                p.setPatientID(rs.getInt(1));
                p.setFirstName(rs.getString(2));
                p.setLastName(rs.getString(3));
                p.setAddress(rs.getString(4));
                p.setHeight(rs.getFloat(5));
                p.setWeight(rs.getFloat(6));
                p.setPhone(rs.getString(7));
                p.setBloodType(rs.getString(8));
                p.setSex(rs.getInt(9));
                p.setBirthDay(rs.getString(10));
                p.setNotes(rs.getString(11));
                p.setEmail(rs.getString(12));
                p.setBenificiary(rs.getInt(13));
                p.setInsuranceDeadline(rs.getString(14));
                v.add(p);
            }
        } catch(SQLException sqle) {
            // Handle exception
            
            throw sqle;
        }
        
        return v;        
    }


}
